home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / PRINTER.ASM < prev    next >
Assembly Source File  |  1986-03-01  |  26KB  |  515 lines

  1. TITLE Printer
  2. PAGE 66,132
  3. ;* * * * * * * * * * * * * *   P R I N T E R   * * * * * * * * * * * * * * *  
  4. ;
  5. ;                             John C. Petrey
  6. ;                                (c) 1983
  7. ;
  8. ;
  9. ;
  10. ;
  11. CSEG    segment para public 'CODE'
  12.         org     100h    
  13. ;
  14. ;
  15. PRINTER proc    far
  16.         assume cs:cseg,ds:cseg,es:nothing
  17. ;
  18.         jmp     set_up
  19. ;
  20. ;Data Area
  21. ;
  22.         disk        db   00h                ;current default disk drive
  23.         bytes_left  db   00h                ;bytes of code left to read
  24.         sav_row     db   02h                ;start cursor at line 2 
  25.         kbd_input   db   ' '                ;save keyboard input
  26.         print_lit   db   'N'                ;flag to indicate if we were printing literal
  27.         option_nbr  db   '0'                ;option number printed on the screen
  28.         fcb         db   00h                ;1st byte of FCB (00h = default drive)
  29.         fcb2        db   'printer '         ;file name in FCB   
  30.         fcb3        db   'dat'              ;file extension in FCB
  31.         fcb4        db    25  dup(00h)      ;remainder of FCB 
  32.         dta         db   128  dup('d')      ;disk transfer area
  33.         eof         db   '$'                ;end of disk transfer area
  34.         codes       db   20  dup('c')       ;user codes
  35.         line1       db   'Printer (1.1) - Special Print Functions$' 
  36.         more        db   'Change another setting? $'      
  37.         nomatch     db   'Please choose an option listed above $'
  38.         quest       db   'Your Choice $'
  39.         option      db   'Option $'
  40.         done        db   ' done!$'
  41.         escape      db   'Esc -  Exit$'
  42.         dash        db   '   -  $'
  43.         no_file     db   'PRINTER.DAT file not found or error in file$'
  44. ;
  45. ;Setup stuff
  46.  set_up:
  47.         push    ds                      ;Set return segment address and ...
  48.         sub     ax,ax                   ;put zero on stack ...
  49.         push    ax                      ;so a RET returns us to starting address.   
  50.         push    cs                      ;Move work address into Data Segment ...
  51.         pop     ds                      ;because this is a COM file.
  52.                                         ;
  53. ;Save registers                         ;By saving register contents at program 
  54.         push    ax                      ;entry we insure exit will correctly
  55.         push    bx                      ;return to DOS.
  56.         push    cx
  57.         push    dx
  58.         sti                             ;enable interrupts
  59.                                         ;
  60. ;Set screen mode
  61.         mov     al,2                    ;80 x 25 B&W alpha
  62.         mov     ah,0                    ;BIOS interrupt 10 - set video mode
  63.         int     10h                     ;call BIOS to do it
  64.                                         ;
  65. ;Clear screen
  66.         mov     ah,6                    ;clear screen with scroll active page up
  67.         mov     al,0                    ;entire window
  68.         mov     cx,0                    ;ch,cl = row,column of upper left corner
  69.         mov     dh,24                   ;dh = row to scroll to
  70.         mov     dl,79                   ;dl = column to scroll to
  71.         mov     bh,7                    ;attribute to be used on blank line
  72.         int     10h                     ;Call BIOS to scroll 
  73.                                         ;
  74. ;Title
  75.         mov     dx,offset line1         ;get address of program title
  76.         call    print                   ;print it on the screen
  77.                                         ;
  78. ;Save current default disk drive
  79.         mov     ah,19h                  ;DOS function to get default drive
  80.         int     21h                     ;Call DOS to do it - returned in AL
  81.         mov     disk,al                 ;Save default disk returned in AL
  82.                                         ;
  83. ;Get drive on which PRINTER.DAT file is located
  84.         mov     si,80h                  ;point to command tail address
  85.         mov     dh,[si]                 ;get length of command tail
  86.         tail:
  87.         cmp     dh,00h                  ;Is their a command tail? or any bytes of tail left?
  88.         je      set_dta                 ;   no, go set DTA
  89.         dec     dh                      ;   yes, update bytes of tail left
  90.         inc     si                      ;        point to next byte in command tail
  91.         mov     dl,[si]                 ;        get contents of command tail       
  92.         cmp     dl,097                  ;Is drive spec upper case?
  93.         jb      upper                   ;   yes, now go fold to a value   
  94.         sub     dl,32                   ;   no, fold down to upper case
  95.         upper:
  96.         sub     dl,65                   ;fold to a value
  97.                                         ;
  98. ;Select disk drive
  99.         cmp     dl,5                    ;if value not valid (a - f) ...
  100.         ja      tail                    ;   get next command tail byte
  101.         cmp     dl,0                    ;if value not valid ...
  102.         jb      tail                    ;   get next command tail byte
  103.         mov     ah,0Eh                  ;DOS function to select disk
  104.         int     21h                     ;call DOS to do it
  105.                                         ;           
  106. ;Set Disk Transfer Address
  107.         set_dta:
  108.         mov     dx,offset dta           ;get address of Disk Transfer Area (DTA)
  109.         mov     ah,1Ah                  ;DOS function to set Disk Transfer Area (DTA)
  110.         int     21h                     ;call DOS to set DTA
  111.                                         
  112. ;Open File Control Block  
  113.         mov     dx,offset fcb           ;point to address of File Control Block (FCB)
  114.         mov     ah,0fh                  ;DOS function to open file control block
  115.         int     21h                     ;call DOS to open file control block
  116.                                         
  117.         mov     bp,00h                  ;initialize base pointer - used later
  118.                                         ;as offset into user codes
  119. ;
  120. ;Sequential read
  121.  read:
  122.         mov     dx,offset fcb           ;get address of file control block
  123.         mov     ah,14h                  ;DOS function to read a record
  124.         int     21h                     ;call DOS to do it.  AL returns 00 if successful.
  125.         cmp     al,00h                  ;Was read successful?
  126.         je      success                 ;  Yes, continue with program
  127.         cmp     al,03                   ;Was partial record read?
  128.         je      success                 ;  Yes, continue with program
  129.         file_not_found:
  130.         mov     dx,offset no_file       ;  No, get address of error message
  131.         call    cursor                  ;      print error message
  132.         jmp     exit                    ;      exit
  133.         success:
  134.                                         ;
  135.         mov     SI,00h                  ;initialize SI to zero - will use SI as offset
  136.                                         ;within DTA (byte were currently working with)
  137.                                         ;
  138.         cmp     dta[si],'&'             ;Is this the end of the users file?
  139.         jne     not_end                 ;  No, still more to read
  140.         jmp     cont                    ;  Yes, we're done reading users file
  141.         not_end:                        ;
  142.                                         ;
  143.         cmp     bytes_left,0            ;Were we reading codes when we reached end of DTA?
  144.         je      not_reading             ;  No
  145.         jmp     read_code               ;  Yes, go finsih reading codes
  146.         not_reading:
  147.                                         ;                                           
  148.         cmp     dta[si],'$'             ;Did we just finish printing a literal when we
  149.                                         ;reached the end of the DTA?
  150.         je      end_of_literal          ;  Yes, now read codes
  151.                                         ;
  152.         cmp     print_lit,'Y'           ;Were we printing the literal when we reached the end of the DTA?
  153.         je      finish_print            ;  Yes,